﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;

//using Bainx.Windows;
//using System.Runtime.InteropServices;
//using System.Diagnostics;
//using System.IO;
//using System.Security.Permissions;



namespace Bainx.Extend
{
    //[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
    
    /// <summary>
    /// 窗体中含有浏览器控件的窗体
    /// </summary>
    public partial class FormWebBrowser : Form
    {

        public WebBrowser WebBrowser
        {
            get { return this.webBrowser; }
        }
        /// <summary>
        /// 窗体中含有浏览器控件的窗体
        /// </summary>
        public FormWebBrowser()
        {
            //base.DlgBgImg = Bainx.Extend.Properties.Resources.DemoDlg1;
            InitializeComponent();
            //SetSkinFile(Properties.Resources.vista11);
           
            
        }
        /// <summary>
        /// 将窗体区域截图
        /// </summary>
        /// <param name="fwb">窗体</param>
        /// <returns>位图</returns>
        public static Bitmap PrintSystemScreen(FormWebBrowser fwb)
        {
            // Create a bitmap
            Bitmap bmp = new Bitmap(fwb.Width,fwb.Height,
                                    PixelFormat.Format32bppPArgb);

            // Create a graphic for drawing from bmp
            Graphics screenG = Graphics.FromImage(bmp);
            screenG.CopyFromScreen(fwb.Location, new Point(0, 0), fwb.Size, CopyPixelOperation.SourceCopy);
            return bmp;
            //screenG.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
            //                       Screen.PrimaryScreen.Bounds.Y,
            //                       0, 0,
            //                       Screen.PrimaryScreen.Bounds.Size,
            //                       CopyPixelOperation.SourceCopy);

            
           
        }
        //public static int static_i = 0;

        //protected override CreateParams CreateParams
        //{
        //    get
        //    {
        //        new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
        //        CreateParams cp = base.CreateParams;
        //        System.Console.WriteLine("========================================");
        //        System.Console.WriteLine("ClssStyle:{0}", cp.ClassStyle.ToString("X"));
        //        System.Console.WriteLine("ExStyle:{0}", cp.ExStyle.ToString("X"));
        //        System.Console.WriteLine("Style:{0}", cp.Style.ToString("X"));
        //        cp.Style = 0x2CF0000;
        //        cp.ExStyle = 0x50000;
        //        cp.ClassStyle = 8;
        //        return cp;
        //    }
        //}
        //private void button1_Click(object sender, EventArgs e)
        //{
        //    //NativeWindow c = new NativeWindow();

        //    Win win = new Win(this.Handle);
        //    FormWebBrowser a = new FormWebBrowser();
        //    //WebBrowser b = new WebBrowser();
        //    //a.Controls.Add(b);
        //    a.webBrowser1.Url = new Uri("http://www.google.com.hk");
        //    a.Show(win);
           
        //}
        //private void SetSkinFile(byte[] bytes)
        //{
        //    memoryStream = new MemoryStream(bytes);
        //    //设置皮肤可以通过两种方式，一种是指定皮肤文件的位置,
        //    //如skinEngine1.SkinFile=fileName(fileName是皮肤文件.ssk文件的位置)
        //    //一种是指定皮肤文件的文件流，如本程序所示
        //    skinEngine.SkinStream = memoryStream;

        //}
        //class Win : System.Windows.Forms.IWin32Window
        //{
        //    public Win(IntPtr Handle)
        //    {
        //        handle = Handle;
        //    }
        //    IntPtr handle;
        //    public IntPtr Handle
        //    {
        //        get { return this.handle; }
        //    }
        //}
    }
}
